// Resources:
// 1) http://msdn.microsoft.com/en-us/library/bb776819(v=VS.85).aspx
// 2) http://msdn.microsoft.com/en-us/library/cc144099(VS.85).aspx


#ifndef __TOOLBARCOMSERVER_H_
#define __TOOLBARCOMSERVER_H_

#include "resource.h"       
#include "ToolbarOwnerWindow.h"

/////////////////////////////////////////////////////////////////////////////

/*
From the MSDN: In addition to IUnknown and IClassFactory, all band objects must implement the following interfaces.

* IDeskBand 
* IObjectWithSite 
* IPersistStream - Guy - seem like this is not really needed

  If the band object is to accept user input, it must also implement IInputObject.
*/

class ATL_NO_VTABLE CToolbarComServer 
	: public CComObjectRootEx<CComSingleThreadModel>
	, public CComCoClass<CToolbarComServer, &CLSID_ToolbarComServer>
	, public IDispatchImpl<IToolbarComServer, &IID_IToolbarComServer, &LIBID_TOOLBARLib>
	, public IObjectWithSite
	, public IDeskBand
	, public IInputObject
{
public:
	CToolbarComServer();
	~CToolbarComServer();

DECLARE_REGISTRY_RESOURCEID(IDR_TOOLBARCOMSERVER)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CToolbarComServer)
	COM_INTERFACE_ENTRY(IToolbarComServer)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(IObjectWithSite)
	COM_INTERFACE_ENTRY(IDeskBand)
	COM_INTERFACE_ENTRY(IDockingWindow)
	COM_INTERFACE_ENTRY(IOleWindow)
	COM_INTERFACE_ENTRY(IInputObject)
END_COM_MAP()

public:
//  IToolbarComServer

//  IObjectWithSite
	STDMETHOD(SetSite)(IUnknown* pUnkSite);
	STDMETHOD(GetSite)(REFIID riid, void **ppvSite);

//  IDeskbend
	STDMETHOD(GetBandInfo)(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO *pdbi);

//  IDockingWindow: The IDeskBand interface inherits from IDockingWindow
	STDMETHOD(CloseDW)(DWORD dwReserved);
	STDMETHOD(ResizeBorderDW)(LPCRECT prcBorder, IUnknown *punkToolbarSite, BOOL fReserved);
	STDMETHOD(ShowDW)(BOOL bShow);

//  IOleWindow: The IDockingWindow interface inherits from IOleWindow. 
	STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode);
	STDMETHOD(GetWindow)(HWND *phwnd);

//  IInputObject
	STDMETHOD(HasFocusIO)();
	STDMETHOD(TranslateAcceleratorIO)(LPMSG lpMsg);
	STDMETHOD(UIActivateIO)(BOOL fActivate, MSG *pMsg);

public:
	void FinalRelease();

protected:
	BOOL CreateToolbarWindow();
	VOID ReleaseResources();

private:
	HWND					m_hwndSiteWindow;
	CToolbarOwnerWindow		m_toolbarOwner;
	DWORD					m_dwBandID;
	DWORD					m_dwViewMode;
	LPCWSTR					m_toolbarTitle;
	IInputObjectSite*		m_inputObjectSite;
	IWebBrowser2*			m_pIWebBrowser2;
	IOleCommandTarget*		m_pIOleCommandTarget;
};

#endif //__TOOLBARCOMSERVER_H_
